﻿using AutoMapper;
using MediatR;
using Microsoft.EntityFrameworkCore.Metadata;
using S.Services.SheepMale.Api.Application.Command.SheepMaleCommand;
using S.Services.SheepMale.Domain.PurchaseSales;
using S.Services.SheepMale.Infrastructure;

namespace S.Services.SheepMale.Api.Application.CommandHandler.SheepMaleCommandHandler
{
    public class SheepFatherExamineCommandHandler : IRequestHandler<SheepFatherExamineCommand, int>
    {
        private readonly IRepository<SheepMaleInfo> repository;

        private readonly IMapper mapper;
        public SheepFatherExamineCommandHandler(IRepository<SheepMaleInfo> repository, IMapper mapper)
        {
            this.repository = repository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(SheepFatherExamineCommand request, CancellationToken cancellationToken)
        {
            var result = repository.GetAsync(request.maleId).Result;
            result.ExamineDate = DateTime.Now;
            result.ExamineBy = "阿星";
            result.ExamineType = true;
            return await repository.UpdateAsync(result);
        }
    }
}
